package com.jlu.easyexcel.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.jlu.easyexcel.domain.Student;
import com.jlu.easyexcel.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
@Scope("prototype")
public class WebStudentListener extends AnalysisEventListener<Student> {

  @Autowired
  StudentService studentService;

  ArrayList<Student> students = new ArrayList<Student>();

  @Override
  public void invoke(Student student, AnalysisContext analysisContext) {

    students.add(student);
//    if (students.size() % 2 == 0){
      studentService.readExcel(students);
      students.clear();
//    }

  }

  @Override
  public void doAfterAllAnalysed(AnalysisContext analysisContext) {

  }
}
